<?php
	//includes
	require_once 'includes.php';
	
	$startTime = microtime() + time();
	
	$wineSearcher = new WineSearcher();
	$vintages = $wineSearcher->GetSavedVintages($_GET['offset'], $_GET['number']);
//	$urls = $wineSearcher->GetEmptyWineURLs();
	
	$result = array('success' => 0, 'fail' => 0);
	
	//saves wines
	$wineItems = array();
	foreach ($vintages as $vintage)
	{
		//wine item
		//$wineItems  = array_merge($wineSearcher->GetWineItems($vintage), $wineItems);
		
		foreach ($wineSearcher->GetWineItems($vintage) as $wineItem)
		{
			//saves the wine into DB
			$saveResult = $wineItem->Save();
			
			//stats
			if ($saveResult)
			{
				$result['success']++;
			}
			else 
			{
				$result['fail']++;
			}
		}		
	}
	
	$endTime = microtime() + time();
	
	//totals
	$resultTime = $endTime - $startTime;
	echo "Total time: $resultTime; Success: {$result['success']}; Fail: {$result['fail']}; ";		
	
?>